﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PropertyManagement.Core;

namespace PropertyManagement.Modal {
    public partial class PersonalInfoEditModal : Form {
        SystemUserManage SystemUserManage { get; set; }
        public PersonalInfoEditModal( ) {
            InitializeComponent( );
            SystemUserManage = new SystemUserManage( );
        }


        private void button1_Click(object sender, EventArgs e) {
            if (GlobalSetting.CurrentSystemUser != null)
            {
                var user = GlobalSetting.CurrentSystemUser;
                if (string.IsNullOrWhiteSpace(textBox1.Text)
                    || string.IsNullOrWhiteSpace(textBox2.Text)
                    || string.IsNullOrWhiteSpace(textBox3.Text)
                    )
                {
                    FormHelper.ShowErrorMsg("你需要填写三个密码问题及其答案才能确保找回密码");
                    return;
                }
                user.PasswordQuestion1 = label1.Text;
                user.PasswordAnswer1 = textBox1.Text.Trim();


                user.PasswordQuestion2 = label2.Text;
                user.PasswordAnswer2 = textBox2.Text.Trim();

                user.PasswordQuestion3 = label3.Text;
                user.PasswordAnswer3 = textBox3.Text.Trim();

                SystemUserManage.Update(user);
                FormHelper.ShowInfoMsg("修改成功！");
            }
            else{
                FormHelper.ShowErrorMsg("当前用户信息错误，请重新登录");
                this.Close();
            }


        }

        private void button2_Click(object sender, EventArgs e) {
            Close( );
        }
    }
}
